<?php // InsightLog.php

class InsightLog {
	
	public static function log($service) {
		$env = json_decode(file_get_contents("/home/dotcloud/environment.json"), true);
		
		if (isset($env['DOTCLOUD_DB_MYSQL_HOST'])) {
			try {
				$mysql = mysql_connect(
					$server = $env['DOTCLOUD_DB_MYSQL_HOST'].':'.$env['DOTCLOUD_DB_MYSQL_PORT'], 
					$username = $env['DOTCLOUD_DB_MYSQL_LOGIN'],
					$password = $env['DOTCLOUD_DB_MYSQL_PASSWORD']
				);
		
				if ($mysql) mysql_select_db('insight_sfdc', $mysql);
				
				$insert = "INSERT INTO log (user_id, org_id, service, timestamp) VALUES('{$_SESSION["user_id"]}','{$_SESSION["org_id"]}','{$service}', NULL)";
				mysql_query($insert, $mysql);
				
				mysql_close($mysql);
			} catch (Exception $e) {}
		}
	}
}

?>